package cn.tedu._05mvcboot03.common.exception;

import cn.tedu._05mvcboot03.common.response.JsonResult;
import cn.tedu._05mvcboot03.common.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public JsonResult IllegalArgumentException(IllegalArgumentException ex){
        log.debug("ex="+ex.getMessage());
        return new JsonResult(StatusCode.OPERATION_FAILED,"文章id必须在1-100之间");
    }
    @ExceptionHandler
    public JsonResult MethodArgumentNotValidException(MethodArgumentNotValidException ex){
        log.debug("ex="+ex.getFieldError().getDefaultMessage());
        return new JsonResult(StatusCode.VALIDATED_ERROR,"标题不能为空... ... 等等");
    }
//    @ExceptionHandler
//    public JsonResult throwable(Throwable throwable){
//        log.debug("t="+throwable.getMessage());
//        return new JsonResult(StatusCode.OPERATION_FAILED);
//    }
}
